
const file_path="/hack_prepare/all-route.txt"

// 方便去重:
var union =[];

function recursion_scan(ns, name , list=[])
{
  let list2 = list.concat([name]);
  if(-1!= union.indexOf(name))
  {
    return;
  }
  else
  {
    union.push(name);
  }
  ns.write(file_path,name+":\n","a");
  var str_route = "";
  for(let i=0;i<list2.length;++i)
  {
    str_route+=list2[i];
    if(i<list2.length-1)
    {
      str_route+=" -> ";
    }
  }// END for
  ns.write(file_path,str_route+"\n","a");
  // 递归扫描:
  var list_of_servers = ns.scan(name);
  for(let i=0;i<list_of_servers.length;++i)
  {
    recursion_scan(ns,list_of_servers[i],list2);
  }// END for

}

export async function main(ns) {
  ns.rm(file_path);
  recursion_scan(ns,'home');
  // var listOfServers = ns.scan("home");
  // for(let i=0;i<listOfServers.length;++i)
  // {

  // }
  ns.tprint("程序运行完毕");
}